<?php
namespace app\index\controller;
use app\common\controller;
class Index extends controller\IndexCommon
{
    public function index()
    {
        $type = input('type');
        if($type){
            $where['a.type'] = $type;
        }
        $list = db('article')->alias('a')
            ->join(tablename('article_type').' b',' b.id=a.type')->where($where)->field('a.*,b.name as tname')->paginate();
        $page = $list->render();
        $list = $list->all();
        foreach ($list as &$v){
            $v['ctime'] = date('Y-m-d',$v['ctime']);
            $v['view'] = $v['view']?:0;
            $v['intro'] = mb_substr(strip_tags($v['content']),0,100);
        }
        $this->assign("list",$list);
        $this->assign("page",$page);
        $types = db('article_type')->select();
        $this->assign("type",$types);
        return $this->fetch();
    }
    public function detail()
    {
        $id = input('id');
        $where['id'] = $id;
        $info = db('article')->where($where)->find();
        $this->assign("info",$info);
        return $this->fetch();
    }
}
